package com.bird.pro.service.impl;

import java.util.ArrayList;
import java.util.List;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.bird.pro.mapper.BirdAdminMapper;
import com.bird.pro.mapper.BirdMenuMapper;
import com.bird.pro.mapper.BirdRmMapper;
import com.bird.pro.pojo.BirdAdmin;
import com.bird.pro.pojo.BirdMenu;
import com.bird.pro.pojo.BirdRm;
import com.bird.pro.pojo.BirdRmExample;
import com.bird.pro.pojo.BirdRmExample.Criteria;
import com.bird.pro.service.IMenuService;

@Service
@Transactional
public class MenuServiceImpl implements IMenuService{

	@Autowired
	private BirdMenuMapper menuMapper;
	@Autowired
	private BirdAdminMapper adminMapper;
	@Autowired
	private BirdRmMapper rmMapper;
	@Override
	public List<BirdMenu> queryMenus(Integer adminId) {
		//查询用户角色id
		BirdAdmin admin = adminMapper.selectByPrimaryKey(adminId);
		//查询所有菜单id
		BirdRmExample example = new BirdRmExample();
		Criteria criteria = example.createCriteria();
		criteria.andRoleIdEqualTo(admin.getRoleId());
		criteria.andRmStateEqualTo("1");
		List<BirdRm> rms = rmMapper.selectByExample(example);
		List<BirdMenu> menus = new ArrayList<>();
		for(BirdRm rm : rms){
			BirdMenu menu = menuMapper.selectByPrimaryKey(rm.getMenuId());
			menus.add(menu);
		}
		
		return menus;
	}

}
